import java.util.Stack;

class MyStack {
    private Stack<Integer> data;  //存放数据的栈
    private Stack<Integer> min;   //存放最小数据的栈

    public MyStack() {
        data = new Stack<>();
        min = new Stack<>();
    }

    //入栈
    public void push(int x) {
        data.push(x);
        if(min.isEmpty() || x<min.peek()) {
            min.push(x);
        } else {
            min.push(min.peek());
        }
    }

    //出栈
    public int pull() {
        min.pop();
        return data.pop();
    }

    //获取栈顶元素
    public int top() {
        return data.peek();
    }

    //获取最小栈
    public int getMin() {
        return min.peek();
    }
}

public class MinStack {
    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(3);
        myStack.push(4);
        myStack.push(2);
        myStack.push(9);
        myStack.push(1);
        myStack.push(7);

        System.out.println(myStack.getMin());

        myStack.pull();
        myStack.pull();

        System.out.println(myStack.getMin());

    }
}
